//
//  YTYGFishpondViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/9/25.
//

#import "YTYGFishpondViewController.h"
#import "fishpondStatisticsModel.h"
#import "AppenSelectViewController.h"
#import "AllQuestViewController.h"
#import "ExamineViewController.h"
#import "YTFishpondHeaderView.h"

#import "MessageViewController.h"


@interface YTYGFishpondViewController ()

///鱼塘名称
@property (nonatomic ,strong) UILabel * YTNamelab;
///报警消息按钮
@property (nonatomic ,strong) UIButton * BJBtn;
///报警消息数量
@property (nonatomic ,strong) UILabel * BJBtnCountlab;
///扫码按钮
@property (nonatomic ,strong) UIButton * SMBtn;
///天气温度
@property (nonatomic ,strong) UILabel * TQWDlab;
///待办红点
@property (nonatomic ,strong) UILabel * DBRedlab;
///任务红点
@property (nonatomic ,strong) UILabel * RWRedlab;
///审批红点
@property (nonatomic ,strong) UILabel * SPRedlab;
///交际红点
@property (nonatomic ,strong) UILabel * JJRedlab;
@property (nonatomic ,strong) UIView * makeview;
@property (nonatomic ,strong) YTFishpondPMDview * pmdview;

///tableviewModel
@property (nonatomic ,strong) fishpondOutdoorModel * tablemodel;
@property (nonatomic ,strong) NSArray <SYMessageListModel *>* messageArray;

@end

@implementation YTYGFishpondViewController

- (void)setMessageArray:(NSArray<SYMessageListModel *> *)messageArray{
    _messageArray = messageArray;
    fishpondOutdoorModel * model = [fishpondOutdoorModel new];
    model.messageArray = messageArray;
    if(model.messageListArray.count > 0){
        self.pmdview.messageArray = model.messageListArray;
        self.makeview.hidden = NO;

    } else {
        self.makeview.hidden = YES;
    }
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadNewData];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupView];
    
    
}

- (void)setupView{
    self.view.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(1, KSCREEN_HEIGHT) direction:GradientColorDirectionVertical startColor:KcolorHex(@"#005ADB") endColor:UIColor.whiteColor];
    UIView * topview = [UIView new];
    [self.view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.left.offset(0);
        make.height.offset(KYiphoneX);
    }];
    MJWeakSelf
    UILabel * YTNamelab = [DTKTool labelWithText:@"养殖场" andFont:kFont(18) andTextColor:UIColor.whiteColor];
    self.YTNamelab = YTNamelab;
    [self.view addSubview:topview];
    [topview addSubview:YTNamelab];
    [YTNamelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.centerY.offset(KTop/2);
    }];
    
    UIImageView * nameimg = kimageView(@"address_selection");
    [topview addSubview:nameimg];
    [nameimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(YTNamelab.mas_right).offset(kwt(8));
        make.centerY.equalTo(YTNamelab);
        make.width.height.offset(kwt(16));
    }];
    
    YTNamelab.addClickBlock(^{
        [weakSelf openBreedFarm];
    });
    nameimg.addClickBlock(^{
        [weakSelf openBreedFarm];
    });
    
    
    UIView * dbview = [UIView new];
    
    dbview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(15) andView:dbview];
    dbview.addClickBlock(^{
        [weakSelf DBViewClick];
    });
    [self.view addSubview:dbview];
    [dbview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.top.equalTo(topview.mas_bottom).offset(kwt(15));
        make.height.offset(kwt(165));
    }];
    
    UIImageView * dbimg = kimageView(@"daiban");
    [dbview addSubview:dbimg];
    [dbimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(26));
        make.width.height.offset(kwt(75));
        make.centerX.offset(0);
    }];
    
    UILabel * DBRedlab = [DTKTool labelWithText:@"0" andFont:kCFont(19) andTextColor:UIColor.whiteColor];
    [dbview addSubview:DBRedlab];
    self.DBRedlab = DBRedlab;
    DBRedlab.textAlignment = NSTextAlignmentCenter;
    [DTKTool YJ:kwt(14) andView:DBRedlab];
    DBRedlab.backgroundColor = KcolorHex(@"#F93A4A");
    [DBRedlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kwt(28));
        make.left.equalTo(dbimg.mas_right);
        make.centerY.equalTo(dbimg.mas_top);
    }];
    
    UILabel * dblab = [DTKTool labelWithText:@"待办事项" andFont:kFont(21) andTextColor:KcolorHex(@"#424242")];
    [dbview addSubview:dblab];
    [dblab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(116));
        make.centerX.offset(0);
    }];
    //
    //
    UIView * RWview = [UIView new];
    RWview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(15) andView:RWview];
    RWview.addClickBlock(^{
        [weakSelf RWViewClick];
    });
    [self.view addSubview:RWview];
    [RWview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-15));
        make.top.width.height.equalTo(dbview);
        make.left.equalTo(dbview.mas_right).offset(kwt(12));
    }];
    
    UIImageView * RDimg = kimageView(@"my_task");
    [RWview addSubview:RDimg];
    [RDimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(26));
        make.width.height.offset(kwt(75));
        make.centerX.offset(0);
    }];
    
    UILabel * RWRedlab = [DTKTool labelWithText:@"0" andFont:kCFont(19) andTextColor:UIColor.whiteColor];
    [RWview addSubview:RWRedlab];
    self.RWRedlab = RWRedlab;
    RWRedlab.textAlignment = NSTextAlignmentCenter;
    [DTKTool YJ:kwt(14) andView:RWRedlab];
    RWRedlab.backgroundColor = KcolorHex(@"#F93A4A");
    [RWRedlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kwt(28));
        make.left.equalTo(RDimg.mas_right);
        make.centerY.equalTo(RDimg.mas_top);
    }];
    
    UILabel * RWlab = [DTKTool labelWithText:@"我的任务" andFont:kFont(21) andTextColor:KcolorHex(@"#424242")];
    [RWview addSubview:RWlab];
    [RWlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(116));
        make.centerX.offset(0);
    }];
    
    UIView * JJview = [UIView new];
    
    JJview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(15) andView:JJview];
    JJview.addClickBlock(^{
        [weakSelf JJViewClick];
    });
    [self.view addSubview:JJview];
    [JJview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dbview.mas_bottom).offset(kwt(12));
        make.left.right.height.width.equalTo(dbview);
    }];
    
    UIImageView * JJimg = kimageView(@"handover");
    [JJview addSubview:JJimg];
    [JJimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(26));
        make.width.height.offset(kwt(75));
        make.centerX.offset(0);
    }];
    
    UILabel * JJRedlab = [DTKTool labelWithText:@"0" andFont:kCFont(19) andTextColor:UIColor.whiteColor];
    [JJview addSubview:JJRedlab];
    self.JJRedlab = JJRedlab;
    JJRedlab.textAlignment = NSTextAlignmentCenter;
    [DTKTool YJ:kwt(14) andView:JJRedlab];
    JJRedlab.backgroundColor = KcolorHex(@"#F93A4A");
    [JJRedlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kwt(28));
        make.left.equalTo(JJimg.mas_right);
        make.centerY.equalTo(JJimg.mas_top);
    }];
    
    UILabel * JJlab = [DTKTool labelWithText:@"交接任务" andFont:kFont(21) andTextColor:KcolorHex(@"#424242")];
    [JJview addSubview:JJlab];
    [JJlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(116));
        make.centerX.offset(0);
    }];
    
    UIView * SPview = [UIView new];
    SPview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(15) andView:SPview];
    SPview.addClickBlock(^{
        [weakSelf SPViewClick];
    });
    [self.view addSubview:SPview];
    [SPview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dbview.mas_bottom).offset(kwt(12));
        make.left.right.height.width.equalTo(RWview);
    }];
    
    UIImageView * SPimg = kimageView(@"examine");
    [SPview addSubview:SPimg];
    [SPimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(26));
        make.width.height.offset(kwt(75));
        make.centerX.offset(0);
    }];
    
    UILabel * SPRedlab = [DTKTool labelWithText:@"0" andFont:kCFont(19) andTextColor:UIColor.whiteColor];
    [SPview addSubview:SPRedlab];
    SPRedlab.textAlignment = NSTextAlignmentCenter;
    self.SPRedlab = SPRedlab;
    [DTKTool YJ:kwt(14) andView:SPRedlab];
    SPRedlab.backgroundColor = KcolorHex(@"#F93A4A");
    [SPRedlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kwt(28));
        make.left.equalTo(SPimg.mas_right);
        make.centerY.equalTo(SPimg.mas_top);
    }];
    
    UILabel * SPlab = [DTKTool labelWithText:@"我的审批" andFont:kFont(21) andTextColor:KcolorHex(@"#424242")];
    [SPview addSubview:SPlab];
    [SPlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(116));
        make.centerX.offset(0);
    }];
    
    UIView * makeview = [UIView new];
    makeview.addClickBlock(^{
        [weakSelf BJBtnClick];
    });
    self.makeview = makeview;
    makeview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJ:kwt(5) andView:makeview];
    [self.view addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.equalTo(JJview.mas_bottom).offset(kwt(12));
        make.height.offset(kwt(75));
    }];
    
    UIImageView * tempimg = kimageView(@"alarm_message1");
    [makeview addSubview:tempimg];
    [tempimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(15));
        make.top.offset(kwt(15));
        make.width.offset(kwt(20));
        make.height.offset(kwt(20));
    }];
    
    YTFishpondPMDview * pmdview = [YTFishpondPMDview initview];
    self.pmdview = pmdview;
    pmdview.userInteractionEnabled = NO;
    [makeview addSubview:pmdview];
    [pmdview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(40));
        make.top.offset(kwt(15));
        make.width.offset(kwt(300));
        make.height.offset(kwt(45));
    }];
    
}

- (void)loadNewData{
    ///获取数据
    [SCNetManger PostHomeAppTaskCountWithDict:@{} andCompetionHandlerBlock:^(HTTPArrBase * model) {
        if(model.code ==200){
            NSArray <appTaskCountModel *>* array = [NSArray yy_modelArrayWithClass:appTaskCountModel.class json:model.result ];
            for (appTaskCountModel * countModel in array) {
                if([countModel.typeName isEqualToString:@"代办事项"]){
                    if(countModel.count > 0){
                        self.DBRedlab.text = [NSString stringWithFormat:@"%d",countModel.count];
                        self.DBRedlab.hidden = NO;
                    } else {
                        self.DBRedlab.hidden = YES;
                    }
                }
                if([countModel.typeName isEqualToString:@"我的任务"]){
                    if(countModel.count > 0){
                        self.RWRedlab.text = [NSString stringWithFormat:@"%d",countModel.count];
                        self.RWRedlab.hidden = NO;
                    } else {
                        self.RWRedlab.hidden = YES;
                    }
                }
                if([countModel.typeName isEqualToString:@"我的审批"]){
                    if(countModel.count > 0){
                        self.SPRedlab.text = [NSString stringWithFormat:@"%d",countModel.count];
                        self.SPRedlab.hidden = NO;
                    } else {
                        self.SPRedlab.hidden = YES;
                    }
                }
                if([countModel.typeName isEqualToString:@"交接任务"]){
                    if(countModel.count > 0){
                        self.JJRedlab.text = [NSString stringWithFormat:@"%d",countModel.count];
                        self.JJRedlab.hidden = NO;
                    } else {
                        self.JJRedlab.hidden = YES;
                    }
                }
            }
        } else {
            [self.view showWarning:model.message];
        }
    }];
    ///当前养殖场
    [SCNetManger PostsysDepartQueryTreeBreedFarmWithDict:[NSMutableDictionary dictionary] andCompetionHandlerBlock:^(HTTPArrBase * model) {
        if(model.code ==200){
            NSArray <PositionsModel *>* array = [NSArray yy_modelArrayWithClass:PositionsModel.class json:model.result ];
            for (PositionsModel * pondmodel in array) {
                if([pondmodel.value isEqualToString:[UserInfoModel shared].OrgCode]){
                    self.YTNamelab.text = pondmodel.label;
                }
            }
        } else {
            [self.view showWarning:model.message];
        }
    }];
    
    ///当前消息
    
    [SCNetManger PostsysSmsAppIndexSmsWithDict:[NSMutableDictionary dictionary] andCompetionHandlerBlock:^(HTTPArrBase * model) {
        if(model.code ==200){
            NSArray <SYMessageListModel *>* array = [NSArray yy_modelArrayWithClass:SYMessageListModel.class json:model.result ];
            self.messageArray = array;
        } else {
            [self.view showWarning:model.message];
        }
    }];
}

- (void)openBreedFarm{
    AppenSelectViewController * vc = [AppenSelectViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}

///交接任务
- (void)JJViewClick{
    NSLog(@"点击交接");
    AllQuestViewController * vc = [AllQuestViewController new];
    vc.isJJ = YES;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
///我的任务
- (void)RWViewClick{
    NSLog(@"点击任务");
    AllQuestViewController * vc = [AllQuestViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
///审批
- (void)SPViewClick{
    NSLog(@"点击审批");
    ExamineViewController * vc = [ExamineViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
///待办
- (void)DBViewClick{
    NSLog(@"点击代办");
    AllQuestViewController * vc = [AllQuestViewController new];
    vc.isDB = YES;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)BJBtnClick{
    MessageViewController * vc = [MessageViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
